<template>
    <el-header>
        <div class="left">
            <el-icon size="25px" color="white" v-show="$store.state.isCollapsed" @click="handleCollapsed()">
                <Expand />
            </el-icon>
            <el-icon size="25px" color="white" v-show="!$store.state.isCollapsed" @click="handleCollapsed()">
                <Fold />
            </el-icon>
            <span style="margin-left: 5px;">我的门户网站管理系统</span>
        </div>
        <div class="right">
            <span>欢迎 {{$store.state.userInfo.username}} 回家！</span>
            <el-dropdown>
                <el-icon size="25px" color="white" class="el-icon--right">
                    <User />
                </el-icon>
                <template #dropdown>
                    <el-dropdown-menu>
                        <el-dropdown-item @click="handleCenter">个人中心</el-dropdown-item>
                        <el-dropdown-item @click="handleLogout">退出</el-dropdown-item>
                    </el-dropdown-menu>
                </template>
            </el-dropdown>
        </div>
    </el-header>
</template>

<script setup>
import { Expand, Fold, User } from "@element-plus/icons-vue"
import { useRouter } from "vue-router";
import { useStore } from "vuex";

const router = useRouter()
const store = useStore()

const handleCollapsed = () => {
    store.commit('changeCollapsed')
}

const handleCenter = () => router.push("/center")


const handleLogout = () => {
    localStorage.removeItem("token")
    store.commit("clearUserInfo")
    router.push("/login")
}
</script>

<style lang="scss" scoped>
.el-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
    background: #2d3a4b;
}

.left,
.right {
    display: flex;
    align-items: center;
}
</style>